<?php
	session_start();
	if(!($_SESSION["username"])||($_SESSION["role"]!="TUT")){
		//not logged in or tutor
		header("location:index.php");
	}
	
	//display message from url
	function message(){
	if(isset($_GET['message'])){
		switch ($_GET['message']){
			case "success":
				echo '<a href="student-email.php"><div id="error" style="display:block;background:#9F9;color:#777;">Email Sent</div></a>';
				break;
			case "fail":
				echo "<a href='student-email.php'><div id='error' style='display:block'>Email Failed to Send</div></a>";
				break;
			}
		}
	}
	
	//export students into dropdown
	function listStudents(){
		
		$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
		$objDB = mysql_select_db("Project 5.5");
		
		$sql="SELECT User_ID, First_Name, Last_Name FROM users WHERE Role='STU'";
		$result=mysql_query($sql);
		
		while ($row = mysql_fetch_row($result)){
			echo "<OPTION value='".$row[0]."'>".$row[1]." ".$row[2]."</OPTION>\n";
		}
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>Email Students</title>
		<script type="text/javascript" src="js/formsValidate.js"/></script>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link href="css/main.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="topbar">
			<div id="qut_logo" />  
			<img src="../img/strapline.png" alt="Slogan" id="slogan"/>
		</div>
		<div id="menubar">
			<div id="breadcrumbs">
				<a href="index.php">Home</a> \ <a href="email.php">Email</a> \ <a href="student-email.php">Student Email</a>
			</div>
			<div id="logout"> 
				<a href="login.php?destroy=true">Log Out</a>
			</div>
		</div>
		
		<?php
			message();
		?>
		
		<a href="student-email.php">
			<div id="error">
			</div>
		</a>
		<div id="namebar_studentemail" ></div>	
		<div id="body">
			
			<form method="post" action="sendemail.php" name="emailform" onSubmit="return validateForm('emailform');">
				<table cellpadding="0" cellspacing="0" align="center" width="100%" height="100%" border="0">
					<tr>
				    <td style="background-color:#58B" width="23%" scope="col" align="center">							
							<div style="color:#FFF">Select Recipients</div><BR />
							<SELECT class="form-login" multiple="multiple" style="height:260px;width:180px;" name="recipients[]">
								<?php
									listStudents();
								?>
							</SELECT>
					  </td>
				    <td width="7%" scope="col" align="center">&nbsp;</td>
						<td width="70%" scope="col" style="text-align:left;padding:15px;"><br />							  
							Subject:
							<input type='text' style="width:200px" name='subject'/>
							
							<br /><br />
							<textarea name="msgtext" style="width:90%;height:180px;"></textarea><br/><br/>
							<input align="" class="SubmitBtn" type="submit" value=""/>
						</td>
					</tr>
				</table>
			</form>
			
		</div>
		<div id="bottombg">
			<p>
				<a style="color:#333" href="http://www.qut.edu.au/additional/privacy">Privacy</a> 
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/copyright">Copyright</a>
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/disclaimer">Disclaimer</a>
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/accessibility">Accessibility</a>
			</p>
		</div>
	</body>
</html>